<style scoped>
.list-main {
  margin: 10px;
}
</style>
<template>
  <div>
    <!-- <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      :immediate-check="false"
      @load="onLoad"
    > -->
      <div class="list-main" v-for="(item, index) in list" :key="index">
        <u-cell-item title="到账金额" :value="'¥' + item.amount" />
        <u-cell-item
          title="提现手续费&服务费"
          :value="item.trans_fee ? item.trans_fee : '-'"
        />
        <u-cell-item
          title="到账账户"
          :value="item.accountno ? item.accountno : '-'"
        />
        <u-cell-item
          title="提现状态"
          :value="
            item.pay_status == 1
              ? '提现成功'
              : item.pay_status == 2
              ? '提现失败'
              : item.pay_status == 3
              ? '提现中'
              : item.pay_status == 4
              ? '审核拒绝'
              : '-'
          "
        />
        <u-cell-item
          title="失败原因"
          :value="item.channel_respmsg == '余额不足' ?  '' : item.channel_respmsg"
        />
        <u-cell-item
          title="提现日期"
          :value="
            item.trans_date +
            ' ' +
            (item.trans_time == null ? '' : item.trans_time)
          "
        />
      </div>
    <!-- </van-list> -->
  </div>
</template>

<script>
import { rechargeList,withdrawList } from "_a/earnings/index";
export default {
  name: "WithdrawalList",
  props: ["query"],
  data() {
    return {
      myQuery: {
        type: "fenrun",
      },
      list: [],
      loading: false,
      finished: false,
      isFirstChange: "today",
    };
  },
  mounted() {
    this.myQuery = this.query;
    this.onLoad();
  },
  methods: {
    resetType() {
      //重置类型,重新请求 ,设置isFirst为默认值
      this.myQuery.isToday = true;
      this.isFirstChange = "today";
    },
    onLoad() {
      this.queryMethod();
    },
    queryMethod() {
      console.log(this.myQuery.page);
      let params = {
        page: this.myQuery.page,
        pageSize: this.myQuery.pageSize,
        startDate: this.myQuery.startTransDate,
        endDate: this.myQuery.endTransDate,
        isToday: this.myQuery.isToday,
        accountType: this.myQuery.type == "qianbao" ? 1 : 3,
      };
      withdrawList(params).then((res) => {
        if (res.code === 200) {
          if (this.isFirstChange == "today" && res.data.isToday == "false") {
            this.myQuery.isToday = false;
            this.isFirstChange = "history";
          }
          if (!this.myQuery.isToday && this.isFirstChange == "history") {
            //如果是否今天W为false,而且isFirstChange为history,代表今天请求的完了,重置页数,在请求历史的
            this.myQuery.page = 1;
            this.queryMethod();
            // console.log('今天请求完毕')
            this.isFirstChange = "over"; //更改为结束标志
          }
          this.$emit("setTotalAmount", res.data.totalAmount);
          if (res.data.list.length > 0) {
            const list = this.list;
            this.list = list.concat(res.data.list);
            // 加载状态结束
            if (!this.myQuery.isToday && this.isFirstChange == "over") {
              //如果是否今天W为false,而且isFirstChange为history,代表今天请求的完了,重置页数,在请求历史的
              console.log("今天请求完毕");
              this.myQuery.page = 1;
              this.isFirstChange = "overPage";
            } else {
              this.loading = false;
              console.log(this.myQuery.page);
              //最终状态到overPage才可以增加页
              if (this.isFirstChange == "overPage" || this.isFirstChange == "today") {
                this.myQuery.page = this.myQuery.page + 1;
              }
            }
          } else {
            //加载状态结束
            this.finished = true;
          }
        }
      });
    },
  },
};
</script>
